<template>
	<view class="">
		<!-- commontext -->
		<view class="main_title">
			能力及业绩
		</view>
		<view class="form_box">
			<view class="input_block flex justify align">
				<view class="input_title">
					服务能力
				</view>
				<view class="input_text">
					<input type="text" v-model="form.service" placeholder="填写服务能力" />
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					垫资能力
				</view>
				<view class="input_text">
					<input type="text" v-model="form.advance_money" placeholder="填写垫资能力" />
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					近2年内工程业绩
				</view>
				<view class="input_text">
					<input type="text" v-model="form.achievement2" placeholder="填写近2年内工程业绩" />
				</view>
			</view>

			<view class="input_block flex justify align">
				<view class="input_title">
					获奖及受表彰情况
				</view>
				<view class="input_text">
					<input type="text" v-model="form.prize" placeholder="填写获奖及受表彰情况" />
				</view>
			</view>
		</view>
		<view class="main_title">
			资金情况
		</view>
		<view class="form_box">
			<view class="input_block flex justify align">
				<view class="input_title">
					资金状况
				</view>
				<view class="input_text">
					<input type="text" v-model="form.money" placeholder="填写资金状况" />
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					期望毛利率
				</view>
				<view class="input_text">
					<input type="text" v-model="form.profit" placeholder="填写期望毛利率" />
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					接受的最低付款比例
				</view>
				<view class="input_text">
					<input type="text" v-model="form.min_pay" placeholder="填写接受的最低付款比例" />
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					材料节约控制的水平
				</view>
				<view class="input_text">
					<input type="text" v-model="form.material" placeholder="填写材料节约控制的水平" />
				</view>
			</view>
		</view>
		<view class="main_title">
			其他
		</view>
		<view class="form_box">
			<view class="input_block flex justify align">
				<view class="input_title">
					供应商资源来源
				</view>
				<view class="input_text">
					<input type="text" v-model="form.source_resources" placeholder="填写供应商资源来源" />
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					可接受的工程区域
				</view>
				<view class="input_text">
					<input type="text" v-model="form.project_area" placeholder="填写可接受的工程区域" />
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					是否接受业主或总包为民企
				</view>
				<view class="input_text flex align flex_right">
					<picker @change="bindPickeris" :value="isInd" :range="isArr">
						<view class="uni-input">{{form.is_private_enterprise}}</view>
						<view class="gray" v-if="!form.is_private_enterprise">
							选择是否接受业主或总包为民企
						</view>
					</picker>
					<image class="right" src="../../static/icon/right2.png" mode="aspectFill"></image>
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					诉讼情况
				</view>
				<view class="input_text">
					<input type="text" v-model="form.lawsuit" placeholder="填写诉讼情况" />
				</view>
			</view>

		</view>
		<view class="main_title">
			诉求说明
		</view>
		<view class="form_box">
			<view class="input_block flex justify align">
				<view class="input_title">
					其余诉求
				</view>
				<view class="input_text">
					<input type="text" v-model="form.other_appeal" placeholder="填写其余诉求" />
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					总结性说明
				</view>
				<view class="input_text">
					<input type="text" v-model="form.summary" placeholder="填写总结性说明" />
				</view>
			</view>
		</view>
		<view class="main_title">
			联系方式
		</view>
		<view class="form_box">
			<view class="input_block flex justify align">
				<view class="input_title">
					姓名
				</view>
				<view class="input_text">
					<input type="text" v-model="form.name" placeholder="填写姓名" />
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					联系电话
				</view>
				<view class="input_text">
					<input type="text" v-model="form.phone" placeholder="填写联系电话" />
				</view>
			</view>
		</view>

		<view class="btn" @tap="sure">
			{{isEdit?'提交修改':'立即发布'}}
		</view>
	</view>

</template>

<script>
	const app = getApp()
	export default {
		data() {
			return {
				id:null,
				isEdit:false,
				isArr: ['是', '否'],
				isInd: -1,
				formObj: {}, //企业信息
				form: {
					service: "", //服务能力
					advance_money: "", //垫资能力
					achievement2: "", //近2年内工程业绩
					prize: "", //获奖及受表彰情况
					money: "", //资金状况
					profit: "", //期望毛利率
					min_pay: "", //接受的最低付款比例
					material: "", //材料节约控制的水平
					source_resources: "", //供应商资源来源
					project_area: "", //可接受的工程区域
					is_private_enterprise: "", //是否接受业主或总包为民企，是/否
					lawsuit: "", //诉讼情况
					other_appeal: "", //其余诉求
					summary: "", //总结性说明
					name: "", //姓名
					phone: "", //电话
				}
			}
		},
		onLoad(options) {
			console.log('===========',options)
			if (options.obj) {
				this.formObj = JSON.parse(options.obj)
			}
			if(options.id) {
				this.isEdit = true
				this.id = options.id
				
				this.getInfo()
			}
			
		},
		onReady() {
			console.log('ready')
			if(this.isEdit){
				uni.setNavigationBarTitle({
					title:'修改企业名片'
				})
			}
			
		},
		methods: {
			// 编辑获取信息
			getInfo(){
				uni.request({
					url: app.globalData.IP + 'addons/shopro/visiting_card/detail',
					data: {
						id:this.id
					},
					header: {
						token: app.globalData.token
					},
					method: 'GET',
					success: res => {
						console.log('修改项目',res)
						if(res.data.code == 1){
							let data = res.data.data
							this.form.service = data.service //服务能力
							this.form.advance_money = data.advance_money //垫资能力
							this.form.achievement2 = data.achievement2 //近2年内工程业绩
							this.form.prize = data.prize //获奖及受表彰情况
							this.form.money = data.money //资金状况
							this.form.profit = data.profit //期望毛利率
							this.form.min_pay = data.min_pay //接受的最低付款比例
							this.form.material = data.material //材料节约控制的水平
							this.form.source_resources = data.source_resources //供应商资源来源
							this.form.project_area = data.project_area //可接受的工程区域
							this.form.is_private_enterprise = data.is_private_enterprise //是否接受业主或总包为民企，是/否
							this.isInd = data.is_private_enterprise=='是'?0:1 
							this.form.lawsuit = data.lawsuit //诉讼情况
							this.form.other_appeal = data.other_appeal //其余诉求
							this.form.summary = data.summary //总结性说明
							this.form.name = data.name //姓名
							this.form.phone = data.phone //电话
						}else{
							uni.showToast({
								title: res.data.msg,
								icon:'none'
							})
							setTimeout(function(){
								uni.navigateBack({delta:1})
							},1000)
						}
					}
				})
			},
			// 
			bindPickerType(e) {
				console.log(e)
				this.isInd = e.detail.value
			},
			// 项目所处阶段
			bindPickerstage(e) {
				console.log(e)
				this.stageInd = e.detail.value
			},
			// 发包人角色
			bindPickerrole(e) {
				console.log(e)
				this.roleInd = e.detail.value
			},
			// 发包类型
			bindPickerwrapType(e) {
				console.log(e)
				this.wrapTypeInd = e.detail.value
			},
			// 合同价格形式
			bindPickeris(e) {
				console.log(e)
				this.isInd = e.detail.value
				this.form.is_private_enterprise = this.isArr[e.detail.value]
			},
			// 建设单位企业性质
			bindPickerenterprise(e) {
				console.log(e)
				this.enterpriseInd = e.detail.value
			},

			// 发布
			sure() {
				if (!this.form.service) {
					uni.showToast({
						title: '请填入服务能力',
						icon: 'none'
					})
					return
				}
				if (!this.form.advance_money) {
					uni.showToast({
						title: '请填入垫资能力',
						icon: 'none'
					})
					return
				}
				if (!this.form.achievement2) {
					uni.showToast({
						title: '近2年内工程业绩',
						icon: 'none'
					})
					return
				}
				if (!this.form.prize) {
					uni.showToast({
						title: '请填入获奖及受表彰情况',
						icon: 'none'
					})
					return
				}
				if (!this.form.money) {
					uni.showToast({
						title: '请填入资金状况',
						icon: 'none'
					})
					return
				}
				if (!this.form.profit) {
					uni.showToast({
						title: '期望毛利率',
						icon: 'none'
					})
					return
				}
				if (!this.form.min_pay) {
					uni.showToast({
						title: '请填入接受的最低付款比例',
						icon: 'none'
					})
					return
				}
				if (!this.form.material) {
					uni.showToast({
						title: '请填入材料节约控制的水平',
						icon: 'none'
					})
					return
				}
				if (!this.form.source_resources) {
					uni.showToast({
						title: '请填入供应商资源来源',
						icon: 'none'
					})
					return
				}
				if (!this.form.project_area) {
					uni.showToast({
						title: '请填入可接受的工程区域',
						icon: 'none'
					})
					return
				}
				if (this.form.is_private_enterprise == -1) {
					uni.showToast({
						title: '请选择是否接受业主或总包为民企',
						icon: 'none'
					})
					return
				}
				
				if (!this.form.name) {
					uni.showToast({
						title: '请填入姓名',
						icon: 'none'
					})
					return
				}
				if (!this.form.phone) {
					uni.showToast({
						title: '请填入电话',
						icon: 'none'
					})
					return
				}
				let params = this.form
				params.enterprise_name = this.formObj.enterprise_name
				params.troops_ids = this.formObj.troops_ids
				params.work_ids = this.formObj.work_ids
				params.person_charge = this.formObj.person_charge
				params.introduce = this.formObj.introduce
				if(this.isEdit){
					params.id = this.id
					uni.request({
						url: app.globalData.IP + 'addons/shopro/visiting_card/edit',
						data: params,
						header: {
							token: app.globalData.token
						},
						method: 'POST',
						success: res => {
							if(res.data.code == 1){
								uni.showToast({
									title: '修改成功',
									duration: 2000
								});
								setTimeout(function(){
									uni.navigateBack({delta:2})
								},1000)
							}else{
								uni.showToast({
									title: res.data.msg,
									icon:'none'
								});
							}
							
						}
					
					})
				}else{
					uni.request({
						url: app.globalData.IP + 'addons/shopro/visiting_card/add',
						data: params,
						header: {
							token: app.globalData.token
						},
						method: 'POST',
						success: res => {
							if(res.data.code == 1){
								uni.showToast({
									title: '添加成功',
									duration: 2000
								});
								uni.switchTab({
									url: '/pages/home/home'
								})
							}else{
								uni.showToast({
									title: res.data.msg,
									icon:'none'
								});
							}
							
						}
					
					})
				}
				
			}
		}
	}
</script>

<style>
	page {
		background: #F7F7F7;
		padding: 30rpx 0;
	}

	.form_box {
		margin: 40rpx 28rpx;
		background-color: #fff;
		border-radius: 20rpx;
		padding: 20rpx 28rpx;
	}

	.input_block {
		margin-bottom: 30rpx;
	}

	.input_block:last-child {
		margin-bottom: 0;
	}

	.input_title {
		color: #000;

	}

	.input_text {
		width: 78%;
		text-align: right;
	}
	.input_text picker{
		width: 78%;
	}

	.input_text .gray {}

	.main_title {
		font-size: 30rpx;
		color: #000;
		padding: 0 28rpx;
		font-weight: 600;
	}

	.btn {
		height: 110rpx;
		line-height: 110rpx;
		text-align: center;
		color: #fff;
		background: var(--base);
		border-radius: 100rpx;
		margin: 60rpx 28rpx 0;
	}
	.flex_right{
		justify-content: flex-end;
	}
</style>
